#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

QT_BEGIN_NAMESPACE
namespace Ui {
class MainWindow;
}
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    void on_start_clicked();
    void on_pause_clicked();
    void on_reset_clicked();
    void on_lap_clicked();
    void on_save_clicked();
    void on_save_as_clicked();
    void on_export_clicked();
    void on_open_clicked();

    void update();

    bool need_save_file();

    void closeEvent(QCloseEvent *event) override;

private:
    void update_ui_labels();
    void file_changed();
    void file_saved();
    void write_csv_file(QString const path);
    void write_json_file(QString const path);
    void read_csv_file(QString const path);
    void add_lap_item(QString const id, QString const timestamp, QString const note);

private:
    Ui::MainWindow *ui;

    QTimer *timer;
    int elapsed;
    int lap_count;
    QString current_timestamp;

    QMenu *popup_menu;

    const QString appname;
    QString filename;
    QString filepath;
    bool is_new_file;
};
#endif // MAINWINDOW_H
